package com.muchfish.reactor.api;

import reactor.core.publisher.Flux;
import reactor.core.publisher.Hooks;

public class ReactorHooksErrorHandlingExample {
    public static void main(String[] args) {
        // 使用 Hooks 进行全局错误处理
        Hooks.onOperatorError((error, reference) -> {
            System.err.println("Global Error Handling: " + error.getMessage());
            return error;
        });

        Flux<Integer> source = Flux.just(1, 2, 0, 4, 5);

        // 流中的错误将被全局处理
        source.map(x -> 10 / x)
                .subscribe(
                        data -> System.out.println("Received: " + data),
                        error -> System.err.println("Subscriber Error: " + error.getMessage())
                );
    }
}
